home *** CD-ROM | disk | FTP | other *** search
- /* Listing 2 - Constructor & Destructor Templates */
-
- CLASS *new_CLASS() {
- SUPER_CLASS *s;
- CLASS *this;
-
- /* Construct super class */
- s = new_SUPER_CLASS();
-
- /* Allocate memory for this object */
- this = calloc(1,sizeof(CLASS));
-
- /* Inherit everything you can from the superclass */
- memmove(this,s,sizeof(CLASS);
-
- /* We're done with the superclass's memory */
- free(s);
-
- /* Assign methods to object */
- this->f1 = f1;
-
- /* Inialize attributes here. Open files, allocate etc.*/
-
- return(this);
- }
-
- void destroy_CLASS(CLASS *this) {
- /* Free any specific data: */
- free(this->p);
-
- /* Close any files specific to this class: */
- fclose(this->file);
-
- /* Call the superclass's destructor */
- destroy_SUPER_CLASS(this);
-
- }
-
- void destroy_SUPER_CLASS(SUPER_CLASS *this) {
- free(this);
- }
-